package com.rds.web.controller.pms;

import com.rds.common.annotation.Log;
import com.rds.common.core.controller.BaseController;
import com.rds.common.core.domain.AjaxResult;
import com.rds.common.core.page.TableDataInfo;
import com.rds.common.enums.BusinessType;
import com.rds.common.utils.poi.ExcelUtil;
import com.rds.system.domain.RdaNameCode;
import com.rds.system.service.IRdaNameCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 编码器Controller
 * @author rds
 * @date 2021-10-12
 */
@RestController
@RequestMapping("/pms/classify/sequence")
public class RdaNameCodeController extends BaseController
{
    @Autowired
    private IRdaNameCodeService rdaNameCodeService;

    /**
     * 查询编码器列表
     */
    @PreAuthorize("@ss.hasPermi('system:namecode:list')")
    @GetMapping("/list")
    public TableDataInfo list(RdaNameCode rdaNamecode)
    {
        startPage();
        List<RdaNameCode> list = rdaNameCodeService.selectRdaNamecodeList(rdaNamecode);
        return getDataTable(list);
    }

    /**
     * 导出编码器列表
     */
    @PreAuthorize("@ss.hasPermi('system:namecode:export')")
    @Log(title = "编码器", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RdaNameCode rdaNamecode)
    {
        List<RdaNameCode> list = rdaNameCodeService.selectRdaNamecodeList(rdaNamecode);
        ExcelUtil<RdaNameCode> util = new ExcelUtil<RdaNameCode>(RdaNameCode.class);
        return util.exportExcel(list, "nameCode");
    }

    /**
     * 获取编码器详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:namecode:query')")
    @GetMapping(value = "/{codeId}")
    public AjaxResult getInfo(@PathVariable("codeId") Long codeId)
    {
        return AjaxResult.success(rdaNameCodeService.selectRdaNamecodeById(codeId));
    }

    /**
     * 新增编码器
     */
    @PreAuthorize("@ss.hasPermi('system:namecode:add')")
    @Log(title = "编码器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RdaNameCode rdaNamecode)
    {
        //rdaNamecode.setId(SnowFlakeUtils.nextId());
        System.out.println("rdaNamecode = " + rdaNamecode);
        return toAjax(rdaNameCodeService.insertRdaNamecode(rdaNamecode));
    }

    /**
     * 修改编码器
     */
    @PreAuthorize("@ss.hasPermi('system:namecode:edit')")
    @Log(title = "编码器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RdaNameCode rdaNamecode)
    {
        return toAjax(rdaNameCodeService.updateRdaNamecode(rdaNamecode));
    }

    /**
     * 删除编码器
     */
    @PreAuthorize("@ss.hasPermi('system:namecode:remove')")
    @Log(title = "编码器", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codeIds}")
    public AjaxResult remove(@PathVariable Long[] codeIds)
    {
        return toAjax(rdaNameCodeService.deleteRdaNamecodeByIds(codeIds));
    }
}
